<template>
	<view v-if="msg==''">
		<xbd-zwnz marginTop='200'></xbd-zwnz>
	</view>
	<view v-else class="center">
		<view class="title">
			{{ msg.title }}
		</view>
		<view class="details">
			<view class="">
				<view class="tag">
					发布人：{{ msg.creator }}
				</view>
				<view class="tag">
					发布时间：{{ msg.created_at | timeFormat('YYYY-MM-DD HH:mm') }}
				</view>
				<view class="tag">
					阅读量：{{ msg.read +1}}
				</view>
			</view>
			<view v-if="!isClick" class="collection" @click="collection">
				<view class="butn">
					<img class="image" src="@/static/image/index/news/collection2.png" alt="">
					<view>收藏</view>
				</view>
			</view>
			<view v-else class="collection click" @click="collection">
				<view class="butn">
					<img class="image" src="@/static/image/index/news/collection1.png" alt="">
					<view>已收藏</view>
				</view>
			</view>
		</view>
		<!-- 富文本编译插件 -->
		<parser :html="msg.content" :tagStyle='style' />
	</view>
</template>

<script>
	import {Index} from '@/api/index.js';
	import {Personalcenter} from '@/api/index.js';

	import parser from '@/components/jyf-parser/jyf-parser.vue';
	export default {

		data() {
			return {
				id: '',
				msg: '',
				isClick: false,
				style: {
					'img': 'display:block;margin: 0 auto;max-width:100%;height:auto; transform: translateX(0);',
					'video': 'width:100%;height:auto;',
				},
			};
		},
		components: {
			parser
		},
		methods: {
			async collection() {
				if (!this.isClick) {
					const res = await Personalcenter.posCollectionCreate(this.id)
					console.log(res)
					this.isClick = !this.isClick
				} else {
					const res = await Personalcenter.posCollectionCancel(this.id)
					this.isClick = !this.isClick
				}
			},
			async init() {
				const res = await Index.getHomeDetail(this.id)
				if(res.success){
					this.msg = res.data
					this.isClick = this.msg.collection
				}else{
					this.$showToast(res.msg);
				}
				
				console.log(res)
				console.log(this.msg)
			}
		},
		async onLoad(res) {
			this.id = res.id
			await this.init()
		}
	}
</script>

<style lang="scss" scoped>
	.center {
		padding: 32rpx;

		.title {
			font-family: PingFang SC, PingFang SC-Heavy;
			font-weight: 800;
			line-height: 56rpx;
			font-size: 32rpx;
			color: #000623;
			text-align: justify;
			word-wrap: break-word;
		}

		.details {
			margin-top: 20rpx 0;
			padding-bottom: 40rpx;
			display: flex;
			justify-content: space-between;
			font-size: 26rpx;
			color: #8890A5;
			align-items: center;
			border-bottom: 2rpx solid #EBEEF5;

			.tag {
				margin-bottom: 10rpx;
			}

			.collection {
				width: 144rpx;
				height: 56rpx;
				border: 2rpx solid #2E73FC;
				border-radius: 30rpx;

				.butn {
					height: 56rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #2E73FC;

					.image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 8rpx;

					}
				}

				&.click {
					border: 2rpx solid #D0D6E5;

					.butn {
						color: #8890A5
					}
				}
			}
		}
	}
</style>
